<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="gae.colopl.*" %>
<%@ page import="gae.colopl.bean.*" %>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- The HTML 4.01 Transitional DOCTYPE declaration-->
<!-- above set at the top of the file will set     -->
<!-- the browser's rendering engine into           -->
<!-- "Quirks Mode". Replacing this declaration     -->
<!-- with a "Standards Mode" doctype is supported, -->
<!-- but may lead to some differences in layout.   -->

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Hello App Engine</title>
  </head>
  
  <body>
    <h2>アイテム倉庫内検索</h2>
    <!-- 
    <div><a href="<%=response.encodeUrl("../index.html") %>">トップ画面</a></div>
     -->
    <div><a href="<%=response.encodeUrl("searchWareHouse.do?type=doc") %>">使い方</a></div>
    <br>
    <form method="POST" action="<%=response.encodeUrl("searchWareHouse.do") %>">
    <%
    String key = "";
    if (request.getParameter("key") != null) {
        key = request.getParameter("key");
    }
    %>
    <%
	    if (key == null) {
    %>
      <div>検索ワード：<input type="text" name="key"></div>
      <%
	    }else {
      %>
      <div>検索ワード：<input type="text" name="key"  value="<%=key %>"></div>
      <%
	    }
      %>
      <input type="hidden" name ="type" value="search">
      <input type="submit" value="検索">
    </form>
    
    <form method="POST" action="<%=response.encodeUrl("setWarehouseItems.do") %>">
    <table border=1>
 <caption>検索結果</caption>
 
 <tr bgcolor="#cccccc">
  <th></th>
  <th>場所</th>
  <th>アイテム名</th>
  <!-- 
  <th>価格</th>
  <th>コメント</th>
  <th>編集</th>
  -->
 </tr>
  <%
  User user = (User)session.getAttribute("userInfo");
  List<WareHouseItem> list = (List<WareHouseItem>)session.getAttribute("warehouse.search.result");
  if (list != null) {
	 if (list.size() > 0) {
	     for (int i = 0; i < list.size(); i++) {
	         WareHouseItem item = list.get(i);
	         String pageUrl = response.encodeUrl("http://colopl.jp/s/itemWH.do?id=" + user.getId() + "&uid=" + user.getUid() + "&guid=ON&point=" + (item.getPageNumber()-1));
	         String editUrl = response.encodeUrl("http://colopl.jp/s/itemOperateWH.do?id=" + user.getId() + "&uid=" + user.getUid() + "&guid=ON&autoID=" + item.getAutoID());
  %>
    <tr align=center>
    <td><input type="checkbox" name="autoID" value="<%=item.getAutoID() %>" checked></td>
    <td><a href="<%=pageUrl %> ">p.<%=item.getPageNumber() %> <%=item.getLineNumber() %>列</a></td>
    <!-- 
    <td><%=item.getLineNumber() %></td>
     -->
    <td><a href="<%=editUrl %>"><%=item.getName() %></a></td>
    <!-- 
    <td><%=item.getPrice() %></td>
    <td><%=item.getComment() %></td>
    <td><a href="<%=editUrl %>">編集</a></td>
    -->
  </tr>  
  <%
	     }
	 } else {
	     out.println("検索ワードを含むアイテムは、アイテム倉庫に入っていません。");
	 }
  }
  String error = (String)session.getAttribute("error");
  if (error != null) {
      out.println(error);
      session.removeAttribute("error");
  }
  %>
</table>
 <%
   if (list != null) {
 %>
<br>
<div>チェックしたアイテムをまとめて設定変更</div>
<div>価格：<input type="text" name="price"></div>
<div>表示プライオリティ：<input type="text" name="priority"></div>
<div>コメント：<input type="text" name="msg"></div>
<input type="submit" value="設定">

<% }%>
</form>

<br>
<br>
    <form method="POST" action="<%=response.encodeUrl("searchWareHouse.do") %>">
      <input type="submit" value="キャッシュのリフレッシュ">
      <input type="hidden" name ="type" value="refresh">
    </form>
    <br>
    <br>
    <div><a href="<%=response.encodeUrl("searchWareHouse.do?type=doc") %>">使い方</a></div>
    <div><a href="<%=response.encodeUrl("menu.do") %>">メニュー</a></div>
    <br>
    <div><a href="<%=response.encodeUrl("logout.do") %>">ログアウト</a></div>
<br>
  </body>
</html>
